<template>
  <el-dialog title="产品新增" width="40%" :before-close="dialogClose" :visible.sync="show">
    <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="物品名称">
          <el-input v-model="form.name" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="物品分类">
          <el-select v-model="form.type" placeholder="物品分类">
            <el-option v-for="(item,index) in cate" :key="index" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物品单价">
          <el-input v-model="form.price"  class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="物品数量">
          <el-input v-model="form.num" type="number" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="应付金额">
          <el-input  class="select_input" :value="form.num*form.price ? form.num*form.price : 0"></el-input>
        </el-form-item>
        <el-form-item label="实付金额">
          <el-input v-model="form.pay_price"  class="select_input"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addSubmit">确 定</el-button>
          <el-button @click="dialogClose">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
</template>
 
<script>
export default {
  name: 'addGoods',
  props:['show'],
  data() {
    return {
        form:{},
        cate:[
          {id:1,name:'院线产品'},
          {id:2,name:'家居产品'}
        ]
    }
  },
  created: function() {
    
  },
  methods: {
    dialogClose:function(){
      this.$emit("func",{'key':'addGoods'})
    },
    addSubmit:function(){
      var that = this
      var validate = {
        name:'物品名称不能为空',
        type:'物品分类不能为空',
        price:'物品单价不能为空',
        num:'物品数量不能为空',
        pay_price:'物品支付价格不能为空'
      }
      for(var x in validate){
        if(!this.form[x]){
          this.$message.error(validate[x]);
          return false;
          break;
        }
      }
      if(this.form.num < 0){
        this.$message.error('物品数量不能小于0');
        return;
      }
      this.form.oa_id = localStorage.getItem('oa_id')
      this.$post('manage/goods/add',this.form).then((res) => {
          if(res.code == 1){
            that.$message.success('添加成功!!!');
            that.$emit("func",{'key':'addGoods','type':1})
          }else{
            that.$message.error(res.msg);
          }
      })
    }
  }
}
</script>
<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
</style>